package com.woniuxy.oa;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TimeZone;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import com.woniuxy.oa.entity.Department;
import com.woniuxy.oa.entity.Employee;
import com.woniuxy.oa.entity.Job;
import com.woniuxy.oa.entity.Personnel;
import com.woniuxy.oa.exception.EmployeeException;
import com.woniuxy.oa.exception.UsernameException;
import com.woniuxy.oa.mapper.DepartmentMapper;
import com.woniuxy.oa.mapper.EmployeeMapper;
import com.woniuxy.oa.mapper.JobMapper;
import com.woniuxy.oa.mapper.PersonnelMapper;
import com.woniuxy.oa.utils.RegexUtil;

@RunWith(SpringRunner.class)
@SpringBootTest
public class GetSql {

	@Test
	public void contextLoads() {
//		Set<String> username = getUsername();
//		List<String> password = getPassword();
//		List<String> name = getName();
//		String gender = getGender();
//		List<String> phone = getPhone();
//		List<String> email = getEmail();
//		List<String> idcard = getIdcard();
//		List<String> bir = getBirByYear(1980);
//		StringBuffer sql = new StringBuffer();
//		String sqlone = "insert into employee (username,`password`,`name`,gender,tellphone,email,idcard,birthday) values ";
//		int index = 0;
//		sql.append(sqlone);
//		for(String str : username) {
//			String sqltwo = "('"+str+"','"+password.get(index)+"','"+name.get(index)+"','"+getGender()+"','"+
//					phone.get(index)+"','"+email.get(index)+"','"+idcard.get(index)+"','"+bir.get(index)+"'),";
//			sql.append(sqltwo);
//			index++;
//		}
//		System.out.println(sql.toString());
	}
	@Test
	public void getPersinnelSql() {
		String[] strs = {"试用期","转正","离职"};
		List<String> bir = getBirByYear(2000);
		StringBuffer sql = new StringBuffer();
		String sqlone = "insert into personnel (id,d_id,j_id,pentrytime,pstatus) values ";
		sql.append(sqlone);
		for(int i=0;i<40;i++) {
			String sqltwo = "("+(i+1)+","+(int) (Math.random()*3+1)+","+(int) (Math.random()*3+1)+",'"+bir.get(i)+"','"+strs[(int) (Math.random()*3)]+"'),";
			sql.append(sqltwo);
		}
		System.out.println(sql.toString());
	}
	
	private Set<String> getUsername(){
		Set<String> set = new HashSet<String>();
		while(set.size() < 10) {
			char[] str = new char[6];
			for(int i=0;i<=5;i++) {
				str[i] = (char) (65 + (int) (Math.random()*26));
			}
			set.add(new String(str));
		}
		return set;
	}
	private List<String> getPassword(){
		List<String> pass = new ArrayList<String>();
		while(pass.size() < 10) {
			char[] str = new char[8];
			for(int i=0;i<=7;i++) {
				str[i] = (char) (97 + (int) (Math.random()*26));
			}
			pass.add(new String(str));
		}
		return pass;
	}
	private List<String> getName(){
		List<String> name = new ArrayList<String>();
		while(name.size() < 10) {
			char[] str = new char[3];
			for(int i=0;i<=2;i++) {
				str[i] = (char) (0x4e00 + (int) (Math.random() * (0x9fa5 - 0x4e00 + 1)));
			}
			name.add(new String(str));
		}
		return name;
	}
	private String getGender() {
		int flag = (int) Math.random()*2;
		if(flag==0) {
			return "男";
		}else {
			return "女";
		}
	}
	private List<String> getPhone(){
		List<String> phone = new ArrayList<String>();
		while(phone.size() < 10) {
			int s = (int) (Math.random()*100000000);
			phone.add("138"+String.format("%08d", s));
		}
		return phone;
	}
	private List<String> getEmail(){
		List<String> email = new ArrayList<String>();
		while(email.size() < 10) {
			int s = (int) (Math.random()*1000000);
			email.add(s+"@163.com");
		}
		return email;
	}
	private List<String> getIdcard(){
		List<String> idcard = new ArrayList<String>();
		while(idcard.size() < 10) {
			char[] card = new char[18];
			for(int i=0;i<=17;i++) {
				card[i] = (char) (Math.random()*10+48);
				
			}
			idcard.add(new String(card));
		}
		return idcard;
	}
	private List<String> getBirByYear(int baseyear){
		List<String> bir = new ArrayList<String>();
		while(bir.size() < 40) {
			int year = (int) (Math.random()*10+baseyear);
			int month = (int) (Math.random()*12+1);
			int day = (int) (Math.random()*28+1);
			bir.add(year+"-"+month+"-"+day);
		}
		return bir;
	}

}
